<?php
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

use Illuminate\Support\Facades\Route;

Route::group(['prefix' => 'common', 'namespace' => 'Common'], function () {
    /**
     * 公共参数/资源
     * @see \App\Http\Controllers\Api\V1\App\Common\ResourceController
     */
    Route::resource('resource', 'ResourceController');

    /**
     * 获取电话的国家区号
     * @see \App\Http\Controllers\Api\V1\App\Common\SendPhoneVerifyCodeController::countryCode()
     */
    Route::get('country-code', 'SendPhoneVerifyCodeController@countryCode');

    /**
     * 发送注册的验证码
     * @see \App\Http\Controllers\Api\V1\App\Common\SendPhoneVerifyCodeController::send()
     */
    Route::post('send-phone-verify-code', 'SendPhoneVerifyCodeController@send');

    /**
     * 境外 IP 服务器向国内发短信，需要境内 IP 服务器代发
     *
     * @see \App\Http\Controllers\Api\V1\App\Common\SendPhoneVerifyCodeController::smsProxy()
     */
    Route::any('sms-proxy', 'SendPhoneVerifyCodeController@smsProxy');

    /**
     * 物流信息订阅
     * @see \App\Http\Controllers\Api\V1\App\Common\LogisticTraceController::subscribe()
     */
    Route::any('logistic-trace/subscribe', 'LogisticTraceController@subscribe');

    /**
     * 物流信息订阅回调处理
     * @see \App\Http\Controllers\Api\V1\App\Common\LogisticTraceController::notify()
     */
    Route::any('logistic-trace/notify', 'LogisticTraceController@notify');

    /**
     * 查询物流
     * @see \App\Http\Controllers\Api\V1\App\Common\LogisticTraceController::index()
     */
    Route::get('logistic-trace', 'LogisticTraceController@index');

    /**
     * 发送重置密码的验证码
     * @see \App\Http\Controllers\Api\V1\App\Common\SendPhoneVerifyCodeController::resetPwdSend()
     */
    Route::post('send-reset-pwd-verify-code', 'SendPhoneVerifyCodeController@resetPwdSend');

    /**
     * 刷新并缓存 jwt Token 给 OpenCart 的页面使用
     * @see \App\Http\Controllers\Api\V1\App\Common\CustomerTokenController::regenerateJwt()
     */
    Route::get('customer/{customer_id}/regenerate-jwt-token', 'CustomerTokenController@regenerateJwt');

    /**
     * 文件上传
     * @see \App\Http\Controllers\Api\V1\App\Common\FileManagerController
     */
    Route::resource('file-manager', 'FileManagerController');
});

/**
 * 用户注册相关
 */
Route::group(['prefix' => 'customer',  'namespace' => 'Customers'], function () {
    /**
     * 客户的注册（手机和邮箱）
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\CustomerRegisterController::register()
     */
    Route::post('register', 'CustomerRegisterController@register');

    /**
     * 返回注册协议
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\CustomerRegisterController::show()
     */
    Route::get('register-agreement', 'CustomerRegisterController@show');

    /**
     * 客户的登录（手机和邮箱）
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\CustomerLoginController::login()
     */
    Route::post('login', 'CustomerLoginController@login');

    /**
     * 第三方登录，pc端（qq，twitter，google，facebook， linkedin）请求授权地址
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\ThirdPartyLoginController::redirectToProvider()
     */
    Route::get('redirect/{type}', ['uses' => 'ThirdPartyLoginController@redirectToProvider', 'https'])->middleware('socialite');

    /**
     * 第三方登录，pc端（qq，twitter，google，facebook， linkedin）授权回调地址
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\ThirdPartyLoginController::handleProviderCallback()
     */
    Route::any('callback/{type}', ['uses' => 'ThirdPartyLoginController@handleProviderCallback', 'https'])->middleware('socialite')->name('pc_oauth_callback');

    /**
     * 第三方登录，返回支付宝的sign
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\ThirdPartyLoginController::generateAliPaySign()
     */
    Route::get('third-party/alipay-sign', 'ThirdPartyLoginController@generateAliPaySign');

    /**
     * 第三方登录接口
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\ThirdPartyLoginController
     */
    Route::resource('third-party', 'ThirdPartyLoginController')->middleware('socialite');

    /**
     * 客户忘记密码，重置新密码
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\ResetPasswordController::resetPwd()
     */
    Route::post('reset-pwd', 'ResetPasswordController@resetPwd');
});


/**
 * App端webview
 */
Route::group(['prefix' => 'home', 'namespace' => 'Webview'], function () {

    /**
     * app端 首页配置信息 和 数据的返回
     *
     * @see \App\Http\Controllers\Api\V1\App\Webview\HomeController::appHome()
     */
    Route::get('/app-home', 'HomeController@appHome');

    /**
     * app端 新闻管理
     *
     * @see \App\Http\Controllers\Api\V1\App\Webview\PressController
     */
    Route::resource('/press', 'PressController');

});

/**
 * 搜索商品, 商品分类
 */
Route::group([], function () {

    /**
     * @see \App\Http\Controllers\Api\V1\App\ProductController::indexAppProducts()
     */
    Route::get('app-product', 'ProductController@indexAppProducts');

    /**
     * @see \App\Http\Controllers\Api\V1\App\ProductController
     */
    Route::resource('product', 'ProductController');

    /**
     * @see \App\Http\Controllers\Api\V1\App\ProductController::searchAutoComplete()
     */
    Route::any('product-search/auto-complete', 'ProductController@searchAutoComplete');

    /**
     * @see \App\Http\Controllers\Api\V1\App\CategoryController
     */
    Route::resource('category', 'CategoryController');

});


/**
 *  App端 商品详情
 */
Route::group(['prefix' => 'product-detail', 'namespace' => 'Product'], function () {

    /**
     * @see \App\Http\Controllers\Api\V1\App\Product\ProductDetailController::show()
     */
    Route::get('/show', 'ProductDetailController@show');

    /**
     * @see \App\Http\Controllers\Api\V1\App\Product\ProductDetailController::indexSpec()
     */
    Route::get('/spec', 'ProductDetailController@indexSpec');

    /**
     * @see \App\Http\Controllers\Api\V1\App\Product\ProductDetailController::indexReviews()
     */
    Route::get('/reviews', 'ProductDetailController@indexReviews');
});

/**
 *  App端 购物车
 */
Route::group(['middleware' => 'AppAuth', 'namespace' => 'Cart'], function(){

    /**
     * 批量删除购物车商品
     * @see \App\Http\Controllers\Api\V1\App\Cart\ShoppingCartController::delete()
     */
    Route::post('/cart/delete', 'ShoppingCartController@delete');

    /**
     * 购物车商品更新选项
     * @see \App\Http\Controllers\Api\V1\App\Cart\ShoppingCartController::updateCartOption()
     */
    Route::post('/cart/cart-option', 'ShoppingCartController@updateCartOption');

    /**
     * @see  \App\Http\Controllers\Api\V1\App\Cart\ShoppingCartController
     */
    Route::resource('/cart', 'ShoppingCartController');
});

/**
 * App端 个人中心
 */
Route::group(['middleware' => 'AppAuth', 'namespace' => 'Customers'], function(){
    /**
     * 客户收藏相关
     * @see \App\Http\Controllers\Api\V1\App\Customers\CustomerWishListController
     */
    Route::resource('/wish', 'CustomerWishListController');

    /**
     * 地址管理
     * @see \App\Http\Controllers\Api\V1\App\Customers\AddressController::createAll()
     */
    Route::get('/address/create-all', 'AddressController@createAll');

    /**
     * @see \App\Http\Controllers\Api\V1\App\Customers\AddressController
     */
    Route::resource('/address', 'AddressController');

    /**
     * @see \App\Http\Controllers\Api\V1\App\Customers\CustomerController::updateCustomer()
     */
    Route::post('/update-customer', 'CustomerController@updateCustomer');

    /**
     * @see \App\Http\Controllers\Api\V1\App\Customers\CustomerController::updatePassword()
     */
    Route::post('/update-password', 'CustomerController@updatePassword');

    /**
     * 显示当前客户信息，App 刷新用
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\CustomerController::showInfo()
     */
    Route::get('/customer-info', 'CustomerController@showInfo');

    /**
     * app个人中心，返回订单类型的统计数量。
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\CustomerController::indexOrderStatistics()
     */
    Route::get('/order-statistics', 'CustomerController@indexOrderStatistics');

    /**
     * App端登录账号扫一扫，pc端自动登录。
     *
     * @see \App\Http\Controllers\Api\V1\App\Customers\ScanQrCodeController::scanQrCode()
     */
    Route::post('/scan-qrcode', 'ScanQrCodeController@scanQrCode');
});

/**
 *  App端 订单管理
 */
Route::group(['middleware' => 'AppAuth', 'namespace' => 'Order'], function(){

    /**
     * @see  \App\Http\Controllers\Api\V1\App\Order\OrderController::paymentMethods()
     */
    Route::get('order/payment-methods', 'OrderController@paymentMethods');

    /**
     * @see  \App\Http\Controllers\Api\V1\App\Order\OrderController::shippingAndPaymentMethods()
     */
    Route::get('order/methods', 'OrderController@shippingAndPaymentMethods');

    /**
     * @see  \App\Http\Controllers\Api\V1\App\Order\OrderController::cancelOrder()
     */
    Route::get('order/cancel-order', 'OrderController@cancelOrder');

    /**
     * @see  \App\Http\Controllers\Api\V1\App\Order\OrderController::confirmOrder()
     */
    Route::get('order/confirm-order', 'OrderController@confirmOrder');

    /**
     * @see  \App\Http\Controllers\Api\V1\App\Order\OrderController::showLogistics()
     */
    Route::get('order/show-logistics', 'OrderController@showLogistics');

    /**
     * @see  \App\Http\Controllers\Api\V1\App\Order\OrderController::indexOrderStatus()
     */
    Route::get('order/order-status', 'OrderController@indexOrderStatus');

    /**
     * App订单修改支付方式
     *
     * @see  \App\Http\Controllers\Api\V1\App\Order\OrderController::patchPayment()
     */
    Route::post('/order/patch-payment', 'OrderController@patchPayment');

    /**
     * @see  \App\Http\Controllers\Api\V1\App\Order\OrderController
     */
    Route::resource('/order', 'OrderController');

    /**
     * 评价管理
     *
     * @see \App\Http\Controllers\Api\V1\App\Order\ReviewController
     */
    Route::resource('/review', 'ReviewController');

    /**
     * 取消售后
     *
     * @see \App\Http\Controllers\Api\V1\App\Order\AfterSaleController::cancelReturnProduct()
     */
    Route::post('/after-sale/cancel', 'AfterSaleController@cancelReturnProduct');

    /**
     * 售后管理
     *
     * @see \App\Http\Controllers\Api\V1\App\Order\AfterSaleController
     */
    Route::resource('/after-sale', 'AfterSaleController');

    /**
     * 返回App支付配置文件
     *
     * @see  \App\Http\Controllers\Api\V1\App\Order\PayConfigController::index
     */
    Route::get('/pay-config', 'PayConfigController@index');

});

/**
 * 支付回调路由
 * @see \App\Http\Controllers\Api\V1\App\Order\PayNotifyController::payCallbackAction()
 */
Route::any('/pay/{gateway}/notify', 'Order\PayNotifyController@payCallbackAction')
    ->name(\App\Http\Controllers\Api\V1\App\Order\PayNotifyController::ROUTE_PAY_NOTIFY_GATEWAY_NAME);

/**
 * pay_pal 重定向空白页，网址带上参数，App拦截获取参数。
 * @see \App\Http\Controllers\Api\V1\App\Order\PayNotifyController::payPalRedirectUrl()
 */
Route::any('/pay/pp_express/redirect', 'Order\PayNotifyController@payPalRedirectUrl')
    ->name(\App\Http\Controllers\Api\V1\App\Order\PayNotifyController::ROUTE_PAY_PAL_REDIRECT_URL);


